package cn.gailvlun.gll.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;

import cn.gailvlun.gll.BuildConfig;
import cn.gailvlun.gll.util.LogUtil;
import cn.gailvlun.gll.util.OnLoginListener;
import cn.gailvlun.gll.util.WechatEvent;



public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        IWXAPI api = WXAPIFactory.createWXAPI(this, BuildConfig.WECHAT_APP_ID, false);
        api.registerApp(BuildConfig.WECHAT_APP_ID);
        api.handleIntent(getIntent(),this);
        finish();
    }

    @Override
    public void onReq(BaseReq baseReq) {
    }

    @Override
    public void onResp(BaseResp baseResp) {
        LogUtil.d("you know what?");
        LogUtil.d("type: " + baseResp.getType() + ", errCode" + baseResp.errCode +
                ", errStr" + baseResp.errStr +
                ", code" + ((SendAuth.Resp) baseResp).code);
        LogUtil.d("after");

        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK: {
                mOnLoginListener.onSuccess(((SendAuth.Resp) baseResp).code);
                break;
            }
            default: {
                
                mOnLoginListener.onFailure("已取消");
                break;
            }
        }
        
        mOnLoginListener = null;
    }

    public static OnLoginListener mOnLoginListener;
}
